<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="topbar::static">
</head>

<body>
<!--引用公用的导航栏-->
<nav th:replace="topbar::topbar"></nav>
<div class="container-fluid">
    <div class="row">
        <div th:replace="topbar::sidebar(activeUri='oscontainerdesc.html')"></div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h1 class="page-header">5GC MANO</h1>
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">
                新增OsContainerDesc
            </button>
            <!--<h2 class="sub-header">Section title</h2>-->
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>osContainerDescId</th>
                        <th>requestedCpuResources</th>
                        <th>requestedMemoryResources</th>
                        <th>cpuResourceLimit</th>
                        <th>memoryResourceLimit</th>
                        <th>swImageDesc</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="oscontainerdesc:${oscontainerdescs}">
                        <td th:text="${oscontainerdesc.osContainerDescId}"></td>
                        <td th:text="${oscontainerdesc.requestedCpuResources}"></td>
                        <td th:text="${oscontainerdesc.requestedMemoryResources}"></td>
                        <td th:text="${oscontainerdesc.cpuResourceLimit}"></td>
                        <td th:text="${oscontainerdesc.memoryResourceLimit}"></td>
                        <td th:text="${oscontainerdesc.swImageDesc}"></td>
                        <td>
                            <button type="button" class="btn btn-danger" aria-label="Left Align"
                                    th:onclick="|deleteOsContainerDesc(${oscontainerdesc.osContainerDescId})|">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!--模态框，用于新增NSD-->
<div id="modal_block" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
     aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增OsContainerDesc</h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <div class="table-responsive">
                        <thead>
                        <tr>
                            <th>osContainerDescId</th>
                            <th>requestedCpuResources</th>
                            <th>requestedMemoryResources</th>
                            <th>cpuResourceLimit</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td><input type="text" class="form-control" id="osContainerDescId"></td>
                            <td><input type="text" class="form-control" id="requestedCpuResources"></td>
                            <td><input type="text" class="form-control" id="requestedMemoryResources"></td>
                            <td><input type="text" class="form-control" id="cpuResourceLimit"></td>
                        </tr>
                        </tbody>
                        <thead>
                        <tr>
                            <th>memoryResourceLimit</th>
                            <th>swImageDesc</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td><input type="text" class="form-control" id="memoryResourceLimit"></td>
                            <td>
                                <select id="swImageDesc" class="selectpicker">
                                    <option class="form-control" th:each="image:${images}" th:value="${image.id}">
                                        <span th:text="${image.name}"></span>:<span th:text="${image.version}"></span>
                                    </option>
                                </select>
                            </td>
                        </tr>
                        </tbody>
                    </div>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="createOsContainerDesc()">保存</button>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var baseUrl = "http://"+hostIp+":8004/oscontainerdesc/";

    function createOsContainerDesc() {
        var url = baseUrl + "create";
        $.ajax({
            url: url,
            type: "POST",
            data: {
                "osContainerDescId": $("#osContainerDescId").val(),
                "requestedCpuResources": $("#requestedCpuResources").val(),
                "requestedMemoryResources": $("#requestedMemoryResources").val(),
                "cpuResourceLimit": $("#cpuResourceLimit").val(),
                "memoryResourceLimit": $("#memoryResourceLimit").val(),
                "swImageDesc": $("#swImageDesc").val()
            },
            complete: function (osContainerDescId) {
                alert("OsContainerDesc创建成功");
                reload();
            }
        });
    }

    function deleteOsContainerDesc(osContainerDescId) {
        var url = baseUrl + "delete";
        $.ajax({
            url: url,
            type: "POST",
            data: {
                "osContainerDescId": osContainerDescId
            },
            complete: function (osContainerDescId) {
                alert("OsContainerDesc删除成功");
                reload();
            }
        });
    }

    function reload() {
        $("#modal_block").modal('hide');
        window.location.reload();
    }
</script>
</html>
